<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class jurnal_umum extends My_Controller
{
	
	function __construct()
	{
		parent::__construct();
				$this->load->model('mdl_jurnal_umum', 'jurnal_umum');		$this->load->model('mdl_master_akun', 'master_akun');		$this->load->library(array('fungsi','pquery'));
		
	}
	
	function index()
	{
		if ($this->can_view() == FALSE){
			redirect('auth/failed');
		}
		
		$data['can_view'] 	= $this->can_view();
		$data['can_insert'] = $this->can_insert();
		$data['can_update'] = $this->can_update();
		$data['can_delete'] = $this->can_delete();
		
		$this->open();
		$param3 = $this->uri->segment(3);		if ($param3==null)			$param3=0;				$data['param3'] = $param3;
		# config pagination
		$config['base_url'] = base_url().'index.php/jurnal_umum/index/';
		
		$config['per_page'] = '10';		$config['num_links'] = '5';		$config['uri_segment'] = '3';				$config['full_tag_open'] = '';		$config['full_tag_close'] = '';				$config['num_tag_open'] = '<div id="page-info">';		$config['num_tag_close'] = '</div>';				$config['cur_tag_open'] = '<div id="page-info"><strong>';		$config['cur_tag_close'] = '</strong></div>';				$config['prev_link'] = '<li class="page-left"></li>';		$config['prev_tag_open'] = '';		$config['prev_tag_close'] = '';				$config['next_link'] = '<li class="page-right"></li>';		$config['next_tag_open'] = '';		$config['next_tag_close'] = '';				$config['last_link'] = '<li class="page-far-right"></li>';		$config['last_tag_open'] = '';		$config['last_tag_close'] = '';				$config['first_link'] = '<li class="page-far-left"></li>';		$config['first_tag_open'] = '';		$config['first_tag_close'] = '';				$config['total_rows'] = $this->jurnal_umum->getItem($config['per_page'], $param3, true);				$this->pagination->initialize($config);	
		# end config pagination
		
		# get data		
		$data['results'] = $this->jurnal_umum->getItem($config['per_page'], $param3, false);
		
		# load view
		$this->load->view('jurnal_umum/jurnal_umum_list', $data);
		
		$this->close();
	}		function insert()	{		if ($this->can_insert() == FALSE){			redirect('auth/failed');		}				$data['can_view'] 	= $this->can_view();			$this->open();		# Data						$akunid			= $this->input->post('akunid');		$debet			= $this->input->post('debet');		$kredit			= $this->input->post('kredit');				# set rules validation		$this->form_validation->set_rules('akunid', 'akunid', 'required');		/*		*/		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');					# set message validation		$this->form_validation->set_message('required', 'Field %s harus diisi!');		$this->form_validation->set_message('numeric', 'Field %s harus diisi hanya dengan angka!');						if ($this->form_validation->run() == FALSE){			//$data['results']=$this->jurnal_umum->get_total_tiap_akun();			$data['glid'] = $this->jurnal_umum->get_glid_ju();			$this->load->view('jurnal_umum/jurnal_umum_add',$data);					}else{			# Data					for ($i=0;$i<count($akunid);$i++){				echo $akunid[$i] . '<br/>';			}					}				$this->close();	}		function get_form_data(){				$data['txtBookName'] = $this->input->post('txtBookName');		$data['authorName'] = $this->input->post('authorName');		echo $data['txtBookName'].'<br/><br/>';		$i=0;		foreach ($data['authorName'] as $rows_author){			echo $i . '-' .$rows_author . '<br/>';			$i++;		}	}		function show_akun(){		/*$data['counter']=$this->uri->segment(3);		$data['result'] = $this->jurnal_umum->get_master_akun();		$this->load->view('jurnal_umum/list_akun2.php', $data);		*/				$data['counter']=$this->uri->segment(3);		$filter=$this->uri->segment(4);		$this->load->view('jurnal_umum/list_akun', $data);	}		function getKodeAkun(){		$parent_pecah = $this->input->post('parent_pecah'); 		$get = $this->jurnal_umum->getKodeAkun($parent_pecah);		 		foreach ($get as $data){			$print = "$data[kode]";			}		echo $print;	}			function show_akun1(){			$data['counter']=$this->uri->segment(3);			$data['result'] = $this->jurnal_umum->get_master_akun();			$this->load->view('jurnal_umum/list_akun1', $data);	}		function show_akun4(){		$data['counter']=$this->uri->segment(3);		$data['result'] = $this->jurnal_umum->get_master_akun4();		$this->load->view('jurnal_umum/list_akun4', $data);	}		function show_akun5(){		$data['counter']=$this->uri->segment(3);		$filter=$this->uri->segment(4);		$data['tahun'] = $this->jurnal_umum->getTahun();		$id="";		$data['result'] = $this->jurnal_umum->get_master_akun2($id);		$this->load->view('jurnal_umum/list_akun5', $data);	}		function get_kas(){			$akunid=$this->uri->segment(3); 				$data_kas = $this->jurnal_umum->get_total_tiap_akun($akunid,false);		$data_kas_count = $this->jurnal_umum->get_total_tiap_akun($akunid,true);				if ($data_kas_count!=0){			$rows=$data_kas->row();			echo $data['data_jml_kas']=$rows->total_kas;		}else{			echo $data['data_jml_kas'] = 0;		}	}		function view_posting_jurnal_umum(){		$glid			= $this->input->post('glid');		$tanggal			= $this->input->post('tanggal');		$akunid			= $this->input->post('akunid');		$nakun			= $this->input->post('nakun');		$debet			= $this->input->post('debet');		$kredit			= $this->input->post('kredit');			for ($i=0;$i<count($akunid);$i++){			$data['akunid'][]=$akunid[$i];			$data['nakun'][]=$nakun[$i];			$data['debet'][]=$debet[$i];			$data['kredit'][]=$kredit[$i];		}		$data['glid'] = $glid;		$data['tanggal'] = $tanggal;		$this->load->view('jurnal_umum/view_posting_jurnal_umum', $data);		}
	function posting_jurnal_umum(){		$glid			= $this->input->post('glid');		$tanggal		= $this->input->post('tanggal');		$akunid			= $this->input->post('akunid');		$nakun			= $this->input->post('nakun');		$debet			= $this->input->post('debet');		$kredit			= $this->input->post('kredit');			$jumlah_pemasukan= $this->input->post('jumlah_pemasukan');			$jumlah_pengeluaran= $this->input->post('jumlah_pengeluaran');			$glid_jurnal_umum=$this->jurnal_umum->get_glid_ju();				$data_ju['glid']=$glid_jurnal_umum;		$data_ju['tanggal']=$tanggal;		$data_ju['jumlah']=$jumlah_pemasukan;		$data_ju['status_posting']='0';				$data_j['glid']=$glid;		$data_j['glid_PARENT']=$glid_jurnal_umum;		$data_j['tanggal']=$tanggal;				for ($i=0;$i<count($akunid);$i++){			$data_dju['glid']=$glid;			$data_dju['tanggal']=$tanggal;			$data_dju['akunid']=$akunid[$i];			$data_dju['debet']=$debet[$i];			$data_dju['kredit']=$kredit[$i];						$data_dj['glid']=$glid;			$data_dj['AKUNID']=$akunid[$i];			$data_dj['debet']=$debet[$i];			$data_dj['kredit']=$kredit[$i];			/*$this->jurnal_umum->insert_detail_j($data_dj);*/			$this->jurnal_umum->insert_detail($data_dju);//detail_jurnal_umum		}		$this->jurnal_umum->insert($data_ju);		/*$this->jurnal_umum->insert_j($data_j);*/	}		function detail_jurnal_umum_list(){		$glid1=$this->uri->segment(3);		$glid2=$this->uri->segment(4);		$glid3=$this->uri->segment(5);		$glid=$glid1.'/'.$glid2.'/'.$glid3;		$data['results'] = $this->jurnal_umum->get_detail_jurnal_umum_list($glid);		$this->load->view('jurnal_umum/view_detail_jurnal_umum_list', $data);	}		function detail_jurnal_umum(){		$glid1=$this->uri->segment(3);		$glid2=$this->uri->segment(4);		$glid3=$this->uri->segment(5);		$glid=$glid1.'/'.$glid2.'/'.$glid3;		$data['results'] = $this->jurnal_umum->get_detail_jurnal_umum($glid);		$this->load->view('jurnal_umum/view_detail_jurnal_umum', $data);	}		function list_posting(){		if ($this->can_view() == FALSE){			redirect('auth/failed');		}		$data['can_view'] 	= $this->can_view();		$data['can_insert'] = $this->can_insert();		$data['can_update'] = $this->can_update();		$data['can_delete'] = $this->can_delete();		$this->open();		$config['base_url'] = base_url().'index.php/jurnal_umum/index/';		$config['total_rows'] = $this->db->count_all('jurnal_umum');		$config['per_page'] = '10';		$config['num_links'] = '5';		$config['uri_segment'] = '3';				$config['full_tag_open'] = '';		$config['full_tag_close'] = '';		$config['num_tag_open'] = '<div id="page-info">';		$config['num_tag_close'] = '</div>';		$config['cur_tag_open'] = '<div id="page-info"><strong>';		$config['cur_tag_close'] = '</strong></div>';				$config['prev_link'] = '<li class="page-left"></li>';		$config['prev_tag_open'] = '';		$config['prev_tag_close'] = '';		$config['next_link'] = '<li class="page-right"></li>';		$config['next_tag_open'] = '';		$config['next_tag_close'] = '';				$config['last_link'] = '<li class="page-far-right"></li>';		$config['last_tag_open'] = '';		$config['last_tag_close'] = '';				$config['first_link'] = '<li class="page-far-left"></li>';		$config['first_tag_open'] = '';		$config['first_tag_close'] = '';				$this->pagination->initialize($config);			$data['results'] = $this->jurnal_umum->get_item_list_unposting($config['per_page'], $this->uri->segment(3));				$this->load->view('jurnal_umum/jurnal_umum_list_unposting', $data);		$this->close();	}		function posting(){		$glid			= $this->input->post('glid');						for ($i=0;$i<count($glid);$i++){						$rows_ju = $this->jurnal_umum->get_item_jurnal_umum($glid[$i]);						foreach ($rows_ju->result() as $rows){				$glid_jurnal = $this->jurnal_umum->get_glid_jurnal();				$data_j['glid']=$glid_jurnal;				$data_j['glid_PARENT']=$rows->glid;				$data_j['tanggal']=$rows->tanggal;				$this->jurnal_umum->insert_j($data_j);										$rows_dju = $this->jurnal_umum->get_detail_item_jurnal_umum($rows->glid);					foreach ($rows_dju->result() as $rows_dju){						$data_dj['glid']=$glid_jurnal;						$data_dj['AKUNID']=$rows_dju->akunid;						$data_dj['debet']=$rows_dju->debet;						$data_dj['kredit']=$rows_dju->kredit;						$this->jurnal_umum->insert_detail_j($data_dj);					}												}						$data['status_posting']='1';			$this->jurnal_umum->update_posting_jurnal_umum($glid[$i],$data);					}		$this->list_posting();			}	function list_akun_tree(){			/*function html_menu(&$strmenu="", $parent=0) {										$query = $this->db->query('select * from master_akun WHERE parent=' . $parent . ' ORDER BY id');					if($query->num_rows() > 0)					{												$strmenu .= '<ul id="navigation">';						foreach($query->result() as $row)						{									$strmenu .= "<li>";									$strmenu .= "<a href='#'>" . $row->akunid . "</a>";									 									//panggil diri sendiri									$this->html_menu($strmenu, $row->id);									$strmenu .= "</li>";						}												$strmenu .= '</ul>';					}					$nilai='1';			}			$strmenu = "";			$this->html_menu($strmenu, 0);			$data['strmenu'] = $strmenu;			$data['nilai'] = $nilai;			$this->load->view('jurnal_umum/list_akun1',$data);*/						echo $this->menu(0,$h="");	}		private function menu($parent=0,$hasil){		$w = $this->db->query("select * from master_akun WHERE parent=' . $parent . ' ORDER BY id");		if(($w->num_rows())>0)		{			$hasil .= "<ul id='navigation'>";		}		foreach($w->result() as $h)		{			$hasil .= "<li>".$h->parent;			$hasil = $this->menu($h->id,$hasil);			$hasil .= "</li>";		}		if(($w->num_rows)>0)		{			$hasil .= "</ul>";		}		return $hasil;	}
}